package net.wang.cloud.user.web;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import net.wang.cloud.dto.OrderDTO;
import net.wang.cloud.user.domain.Customer;
import net.wang.cloud.user.feign.OrderFeign;
import net.wang.cloud.user.service.CustomerService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "api/customer")
@Slf4j
public class CustomerController {

    @Resource
    CustomerService customerService;
    @Resource
    OrderFeign orderFeign;

    @PostMapping(value = "/save")
    public Object save() {
        return customerService.save();
    }

    @GetMapping(value = "/all")
    //启用性能监控数据收集
    @HystrixCommand
    public List<Customer> findAll() {
        return customerService.all();
    }

    @GetMapping(value = "/my")
    public Map<String, Object> getInfo() {
        OrderDTO order = orderFeign.getOrder(1L);
        log.info("order : {}", order);
        Map<String, Object> map = new HashMap<>();
        map.put("data", order);
        return map;
    }
}
